package com.zhdl;

import com.zhdl.hardware.motor.huichuan.repository.impl.HcPortCmdHandle;
import com.zhdl.hardware.motor.leisai.repository.impl.LeisaiPortCmdHandleDaoImpl;
import com.zhdl.hardware_modules.service.DeviceService;
import com.zhdl.network.service.impl.WaterMeterServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.Resource;

@Slf4j
@EnableAsync
@EnableScheduling
@SpringBootApplication(scanBasePackages = {"com.zhdl", "com.project"})
public class AppApplication extends SpringBootServletInitializer implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(AppApplication.class);
        app.addListeners(new ApplicationPidFileWriter());
        app.run(args);
    }

    @Override
    protected WebApplicationContext run(SpringApplication application) {
        return super.run(application);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return super.configure(builder);
    }

    @Resource
    private DeviceService deviceService;

    @Resource
    private HcPortCmdHandle hcPortCmdHandle;

    @Resource
    private LeisaiPortCmdHandleDaoImpl leisaiPortCmdHandleDao;

    @Resource
    private WaterMeterServiceImpl waterMeterService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        deviceService.hardwareInit();
//        leisaiPortCmdHandleDao.addPort("1");
    }

}
